﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using IBS.Bll;
using IBS.Bll.KnowledgeBase;
using Ninject;
using IBS.ServiceContracts;
using IBS.Bll.Tests;

namespace BankApp.ExtraMvc
{
    public class BankAppControllerFactory : DefaultControllerFactory
    {
        private IKernel ninjectKernel;

        public BankAppControllerFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        private void AddBindings()
        {
            var servicesFactory = new ServicesFactory();
            ninjectKernel.Bind<IAccountService>().ToConstant(servicesFactory.GetInstance<IAccountService>());
            ninjectKernel.Bind<IAddressService>().ToConstant(servicesFactory.GetInstance<IAddressService>());
            //ninjectKernel.Bind<IAutoPaymentService>().ToConstant(servicesFactory.GetInstance<IAutoPaymentService>());
            ninjectKernel.Bind<IAuthorityService>().ToConstant(servicesFactory.GetInstance<IAuthorityService>());
            ninjectKernel.Bind<ICurrencyService>().ToConstant(servicesFactory.GetInstance<ICurrencyService>());
            ninjectKernel.Bind<IKnowledgeBaseService>().ToConstant(servicesFactory.GetInstance<IKnowledgeBaseService>());
            ninjectKernel.Bind<IPaymentService>().ToConstant(servicesFactory.GetInstance<IPaymentService>());
            ninjectKernel.Bind<IStreetService>().ToConstant(servicesFactory.GetInstance<IStreetService>());
            ninjectKernel.Bind<ICardService>().ToConstant(servicesFactory.GetInstance<ICardService>());
            ninjectKernel.Bind<ITransferService>().ToConstant(servicesFactory.GetInstance<ITransferService>());
            ninjectKernel.Bind<IBillService>().ToConstant(servicesFactory.GetInstance<IBillService>());
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return (controllerType == null) ? null : (IController)ninjectKernel.Get(controllerType);
        }
    }
}
